package com.pipi.mq.rocketmq.base.producer;

import com.pipi.mq.rocketmq.base.config.PropertiesConfig;
import com.pipi.mq.rocketmq.base.producer.config.ProducerConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.concurrent.CountDownLatch;

/**
 * @Package com.pipi.mq.rocketmq.base
 * @author: 皮皮（pipi@maihaoche.com）
 * @date: 2020/4/18 2:55 PM
 */
public class ProducerStarter {

    private static volatile CountDownLatch countDownLatch = new CountDownLatch(1);

    public static void main(String[] args) throws Exception {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ProducerConfig.class, PropertiesConfig.class);


        try {
            SyncProducer syncProducer = applicationContext.getBean(SyncProducer.class);
            syncProducer.syncSendThread(countDownLatch);


//            AsyncProducer asyncProducer = applicationContext.getBean(AsyncProducer.class);
//            asyncProducer.asyncSendThread(countDownLatch);

//
//            OneWayProducer oneWayProducer = applicationContext.getBean(OneWayProducer.class);
//            oneWayProducer.oneWaySendThread(countDownLatch);
        } finally {
            countDownLatch.await();
            applicationContext.close();
        }

    }
}
